package com.bite.forum.controller;

import com.bite.forum.common.AppResult;
import com.bite.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

@Api(tags = "test类接口------------")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1， 显示你好 Spring boot")
    @GetMapping("/hello")
    public String hello() {
        return "Hello, Spring Boot...";
    }

    @ApiOperation("测试接口4， 按传入的姓名显示hallo信息")
    @PostMapping("/helloByname")
    public AppResult helloByname(@ApiParam("姓名") @RequestParam("name") String name){
        return AppResult.success("hello : " + name);
    }

    @ApiOperation("测试接口2， 显示抛出的自定义异常的信息")
    @GetMapping("/appException")
    public AppResult testApplicationException (){
        throw new ApplicationException("这是一个ApplicationException...");
    }

    @ApiOperation("测试接口3， 显示抛出异常的信息")
    @GetMapping("/exception")
    public AppResult exception () throws Exception {
        throw new Exception("这是一个Exception...");
    }
}
